 $(document).ready( function() {
  //  退出解析页面
  $(".btn-exit").click(function(e) {
    e.preventDefault();
    e.stopPropagation();
    window.close();
  })
	//显示答题卡
	$(".hasShowCardLink").click(function(e) {
        $("#numberCardDom").show();
		$("#maskDiv").show();
		$("html,body").animate({scrollTop:"0"},10);
		//$("#content").hide();
    });
	//隐藏答题卡
	$(".card-off").click(function(e) {
        $("#numberCardDom").hide();
		$("#maskDiv").hide();
		//$("#content").show();
    });
	//隐藏答题卡同时定位锚点
	$("a.iconBox").click(function(e) {
		e.stopPropagation();
		//e.preventDefault();
		var pageId = $(this).attr("questionsIdHref");
        $("#numberCardDom").hide();
		$("#maskDiv").hide();
		//$("#content").show();
		$("html,body").animate({scrollTop:$("[questionsId="+pageId+"]").offset().top-200},200);
    });
	//试题内容第一个P标签加样式
	$(".answers").each(function(index, element) {
        $($(this).find("p")[0]).css("display","inline");
    });
	$(".questionsContent").each(function(index, element) {
        $($(this).find("p")[0]).css("display","inline");
    });
	//左侧导航判断是否回答正确
	$("a.iconBox").each(function(index, element) {
        if($(this).attr("hasAnswered")=="error"){
			$(this).removeClass("icon_answer_answered").addClass("icon_answer_error");
			$(this).parent("dd").removeClass("s3").addClass("s4");
		}else if($(this).attr("hasAnswered")=="deleted") {
      $(this).removeClass("icon_answer_answered").addClass("icon_answer_deleted");
			$(this).parent("dd").removeClass("s3").addClass("s5");
		}
    });
	//对错标志
	$(".questionsContent .error").each(function(index, element) {
        if($(this).attr("hasAnswered")=="right"){
			       $(this).removeClass("hasError").addClass("hasOk");
             $(this).parents(".questionsContent").find(".a_wg").removeClass("hasError").addClass("hasOk");
		    }else if($(this).attr("hasAnswered")=="deleted") {
          $(this).removeClass("hasError").addClass("hasDeleted");
          $(this).parents(".questionsContent").find(".a_wg").removeClass("hasError").addClass("hasDeleted");
		    }
    });
	//判断是否答过，标记答案
	$(".questionsContent").each(function(index, element) {
		if($(this).find("input[name=questionsType]").val()=="1"||$(this).find("input[name=questionsType]").val()=="2"||$(this).find("input[name=questionsType]").val()=="3"){
			if($(this).attr("hasAnswered")=="true"){
				var list = $(this).find("input[name=questionsAnswered]").val();
				list = list.split(",");
				var checkInput = $(this).find("input.radioOrCheck");
				checkInput.each(function(index, element) {
					var obj = $(this);
                    var name = obj.attr("answerName");
					$.each(list, function(index, value) {
						if(value == name){
							obj.prop("checked",true);
						}
					});
                });
			}
		}
    });
	//移除错题
	$(".removeBtn").click(function(e) {
		var test_id = $(this).attr("test_id");
		var test_type = $(this).attr("test_type");
    	var dataForm = "test_id="+test_id+"&test_type="+test_type+"&exam_info_id="+exam_info_id;
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "/exam/remove_error",
			data: dataForm,
			success: function(msg){
				if(msg.msg=="True"){
					window.location.reload();
				}else{
					alert("操作失败，请联系管理员！");
				}
			}
		});
	});

    /*
   //问答题初始化编辑器
    $("textarea[class=keyCloze]").each(function(index, element) {
        var id = $(this).attr("id");
        UE.getEditor(id, {
            toolbars:[],
            wordCount:false, //关闭字数统计
            elementPathEnabled:false, //关闭elementPath
            autoHeightEnabled:true,
            initialFrameHeight:130,
            lang:'zh-cn' //语言
        })
    });
    */

    $("input[name=score]").blur(function() {
        var val = $(this).val();
        if(val==""){
            alert("分数不能为空！");
            $(this).focus();
        }
        if(val < 0 || val % 0.5 != 0){
            alert("分数只能为大于等于0的0.5的倍数！");
            $(this).focus();
        }
    });
    $("input[name=score]").on("click", function () {
       $(this).select();
    });
});

/*
$("#save_answer_btn").click(function(){
		var answer_all = [];
		$(".questionsContent").each(function(index, element){
			var question_id = $(this).attr("questionsid");
			var question_type = $(this).find(".radioOrCheck").attr("questionstype");
			var keyList = "";
            console.log(question_type);
			if(question_type=="1"){ //单选
				$($(this).find(".radioOrCheck")).each(function(index, element) {
					if($(this).is(":checked")){
						keyList = $(this).attr("answerName")+",";
						return;
					}
				});
                console.log(keyList);
			}
			else if(question_type=="2"){ //多选
				$($(this).find(".radioOrCheck")).each(function(index, element) {
					if($(this).is(":checked")){
						keyList += $(this).attr("answerName")+",";
					}
				});
			}
			else if(question_type=="3"){ //判断
				$($(this).find(".radioOrCheck")).each(function(index, element) {
					if($(this).is(":checked")){
						keyList = $(this).attr("answerName")+",";
					}
				});
			}
			var single_data = {"test_id":question_id,"test_ans":keyList,"exam_results_id":exam_results_id,"exam_info_id":exam_info_id};
			answer_all.push(single_data);
		});
		exam_test_list = JSON.stringify(answer_all);
		//将分割URI的&符号转义为十六进制序列
		exam_test_list = encodeURIComponent(exam_test_list);
		var dataForm = "exam_test_list="+exam_test_list;
		$.ajax({
			type: "POST",
			dataType: "json",
			url: "/exam/exam_start_ing_multi",
			data: dataForm,
			processData: false,
			success: function(msg){
				if(msg.success=="True"){
					alert("保存成功");
				}
				else{
					alert("操作失败，请联系管理员！");
				}
			}
		})
	})
*/
